/**
 * 登录模块，提供登录相关业务功能
 * 
 * @Date: 2015-6-16
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "datagridServ","msgServ", "ajaxServ", "formServ", "bizProto"],
		function($,datagridServ, msgServ, ajaxServ, formServ, bizProto) {

			'use strict';

			var _bizProto,_buttonConfig,
				//锚记datagrid目标元素
				$dg,
				//初始化后的datagrid dom对象
				$grid,
				//编辑弹窗对象及弹窗按钮对象
				$edit_window,window_btn,
				//设置密码弹窗对象及按钮对象
				$password_window,password_btn,
				//业务表单对象
				$form,
				//部门选择框字段
				$deptNameField, $deptIdField,formEl, formData = 0, 
				 
				roleSaveUrl = '/roleSave.action', 	baseSaveUrl		
				

			var public_method = {
				
				
				init:function(doc){
					private_method.init(doc);
				}
				
			}

			var private_method = {
				init : function(doc) {
					if (window.console) {
					console.info('user modules gets ready and been loaded.');
					}
					_bizProto = new bizProto({doc:doc,rootId:'panel-permissionAssign',panelSelector:'div.well'})
					_buttonConfig={						
						 "保存":private_method.submit,
						 "取消":private_method.cancel									
					}
					private_method.initPath();
					private_method.initElement(_bizProto.pageDoc)
				},
				
				//初始化路径
				initPath:function(){
					
					baseSaveUrl = _bizProto.rootPath + roleSaveUrl;	
					
				},
				
				
				//初始化元素
				initElement:function(doc){
					
					
					$grid = $(doc).find("#dg-rolePermission-role");
					
					// 编辑窗口初始化
					$edit_window = $('#roleEdit-win');
					window_btn = $($edit_window).find('a.function-btn')
					$(window_btn).unbind('click')
					$(window_btn).bind('click',	private_method.function_btn_listenner)
					$form = $($edit_window).find('form')					
					
					var selectedRecord = $grid.datagrid('getSelected');
					
					if(selectedRecord.parentid==null)						
						selectedRecord.parentid='';
					var addFlag = $($edit_window).attr('flag');
					if(addFlag==null)
						$form.form('load',selectedRecord);

				},				
				
				//功能按钮监听函数
				function_btn_listenner:function(e){
					
					btnServ.applyButton({buttonEvt:e,buttonConfig:_buttonConfig})
					
				},			
				
				// 提交form
				submit : function() {
					
					datagridServ.save({form:$form,grid:$grid,url:baseSaveUrl})					
				},				
				
				//
				cancel : function() {
					$($edit_window).window('close');
				}
			};
			
			return public_method;

		});